// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出计算属性 ============================== //

export default {
  // —————————————————————————————— 计算属性 —————————————————————————————— //

  /**
   * 自定义计算属性 (可覆盖)
   */
  GETTER: ({ param: { deviceCategoryId }, list, selectParam }) => {
    const STATUS = CORE.DICT[`STATUS_MAP_${transName(deviceCategoryId)}`]
    const otherStatus = STATUS.slice(1).map((item) => `${item[0]}`)

    const first = list.reduce((count, { objectRunStatus: status }) => {
      return otherStatus.includes(`${status}`) ? count : count + 1
    }, 0)

    const getOther = (value) => list.reduce((count, { objectRunStatus: status }) => {
      return `${status}` === `${value}` ? count + 1 : count
    }, 0)

    return {
      STATUS: STATUS.map((dict, i) => [...dict, !i ? first : getOther(dict[0])]),
      isVideo: deviceCategoryId === '1', // 是否为视频点位
      isLine: !!selectParam.deviceCategoryId, // 是否为周界线
    }
  },
}

// ============================== 内部方法 ============================== //

export const transName = (deviceCategoryId) => {
  switch (deviceCategoryId) {
    case '2': return 'ACCESS'
    case '3': return 'PARKING'
    case '4': return 'DEFENCE'
    case '5': return 'HVAC'
    case '7': return 'LIGHT'
    case '16': return 'PATROL'
    case '24': return 'FIREFIGHTING'
    default: return 'DEVICE'
  }
}
